﻿using Kw.Combinatorics;
using System;

namespace Kw.CombinatoricsExamples
{
    class PermutationExample03
    {
        static void Main ()
        {
            int width = 6;
            long rank = 9;

            // Create a permution with a supplied rank:

            Permutation pn = new Permutation (width, rank);
            Console.WriteLine ("{0}  rank={1}", pn, pn.Rank);

            // Assign -1 to Rank to get the last rank:

            pn.Rank = -1;

            // A row can be treating as a string:

            string text = pn.ToString() + "  last rank=" + pn.Rank;
            Console.WriteLine ("\n" + text);

            // Rank will always stay in bounds:

            ++pn;
            Console.WriteLine ("\n{0}  rank={1}", pn, pn.Rank);

            // Create a permutation from a known sequence:

            pn = new Permutation (new int[] { 5, 0, 3, 1, 2, 4 });
            Console.WriteLine ("\n{0}  rank={1}", pn, pn.Rank);
        }

        /* Output:

        { 0, 1, 3, 4, 5, 2 }  rank=9

        { 5, 4, 3, 2, 1, 0 }  last rank=719

        { 0, 1, 2, 3, 4, 5 }  rank=0

        { 5, 0, 3, 1, 2, 4 }  rank=612

        */
    }
}
